<template>
	<view>
		<view class="jc-center ">
			<view @click="getvideo()" class="w100 tc radius20 ml50">点击</view>
		</view>
		<view>{{wql}}</view>
	</view>
</template>
<script setup>
	import {
		BrowserCodeReader
	} from '@zxing/library';
	import {
		ref
	} from 'vue';
	const wql = ref()
	const getvideo = async() => {
		try {
			// 获取用户媒体设备（摄像头）的视频流
			const stream = await navigator.mediaDevices.getUserMedia({
				video: true
			});
			// 将视频流赋值给<video>元素的srcObject属性
			const videoElement = document.getElementById('video');
			videoElement.srcObject = stream;
			// 播放视频
			videoElement.play();
		} catch (error) {
			console.error('调用摄像头失败:', error);
			// 处理用户拒绝访问摄像头等错误
			alert('调用摄像头失败，请检查权限设置');
		}

	}
</script>